#include <stdio.h>

#include "SDL.h"
#include "Game.h"
#include "PlayState.h"

PlayState PlayState::m_PlayState;

void PlayState::Init()
{       
		player = new Player(); // Now we create a player
		player->Load("naruto.bmp");

		gameobject = new GameObject();
		gameobject->Load("ryuk.bmp");

		GameObjects.push_back(gameobject);
		GameObjects.push_back(player); // Push the newly created player onto the vector

        printf("PlayState Init Successful\n");
}

void PlayState::Clean()
{
	for(unsigned int i = 0; i < GameObjects.size(); i++) {
		if(!GameObjects[i]) continue;

		GameObjects[i]->Clean();
	}

        printf("PlayState Clean Successful\n");
}

void PlayState::Pause()
{
        printf("PlayState Paused\n");
}

void PlayState::Resume()
{
        printf("PlayState Resumed\n");
}

void PlayState::HandleEvents(Game* game)
{
        SDL_Event event;
        
        if (SDL_PollEvent(&event)) {
                switch (event.type) {
                        case SDL_QUIT:
                                game->Quit();
                                break;

						case SDL_KEYDOWN:
							switch(event.key.keysym.sym) {
							case SDLK_RIGHT: {
								break;
											 }
							}
                }
        }
}

void PlayState::Update(Game* game) 
{
	for(unsigned int i = 0; i < GameObjects.size(); i++) {
		if(!GameObjects[i]) continue;

		GameObjects[i]->Update();
	}
}

// We have to change the way we get the screen in this function
void PlayState::Draw(Game* game) 
{
	SDL_FillRect(game->GetScreen(), NULL, 0x000000);
	
	for(unsigned int i = 0; i < GameObjects.size(); i++) {
		if(!GameObjects[i]) continue;

		GameObjects[i]->Draw();
	}

	SDL_Flip(game->GetScreen());
}